package com.more.offer.designpatterns.singleton.lazyinitialization;

import javax.annotation.concurrent.ThreadSafe;

/**
 * @author pinoc
 * @date 2021/10/22
 * @description
 * 双重检查的方式 并且性能比直接锁方法要高
 */
public class ThreadSafeLazySingleton {

	private static ThreadSafeLazySingleton instance;

	private ThreadSafeLazySingleton(){}

	public static ThreadSafeLazySingleton getInstance(){
		if(instance == null) {
			synchronized (ThreadSafeLazySingleton.class) {
				if( instance == null) {
					instance = new ThreadSafeLazySingleton();
				}
			}
		}
		return instance;
	}
}
